// pages/member/rankingListSecond/rankingListSecond.js
var app = getApp();
Page({

  /**
	 * 页面的初始数据
	 */
  data: {
    recordsList: [],
    activeName: 0,
    currentTabIndex: 0,
    name: '',
    //more
    isLoadMore: true,
    page: 1,
    total_page: 0,
  },

  /**
	 * 生命周期函数--监听页面加载
	 */
  onLoad: function (options) {
    this.getName();
    this.getData();
  },

  /**
	 * 生命周期函数--监听页面初次渲染完成
	 */
  onReady: function () {

  },

  /**
	 * 生命周期函数--监听页面显示
	 */
  onShow: function () {

  },

  /**
	 * 生命周期函数--监听页面隐藏
	 */
  onHide: function () {

  },

  /**
	 * 生命周期函数--监听页面卸载
	 */
  onUnload: function () {

  },

  /**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
  onPullDownRefresh: function () {

  },

  /**
	 * 页面上拉触底事件的处理函数
	 */
  onReachBottom: function () {

  },

  /**
	 * 用户点击右上角分享
	 */
  onShareAppMessage: function () {

  },
  getUsable() {
    let urlStr = app.getNetAddresss("plugin.coin.Frontend.Controllers.page.index");
    app._getNetWork({
      url: urlStr,
      success: (res) => {
        if (res.data.result === 1) {
          this.setData({
            usable: res.data.data.usable,
            coin_name: res.data.data.coin_name
          });

        } else {
          wx.showToast({
            title: res.data.msg,
            icon: "none"
          });
        }
      },
      fail: function (res) {
        console.log(res);
      }
    });
  },
  getName() {
    let urlStr = app.getNetAddresss("plugin.integral.Frontend.Controllers.page.get-name");
    app._getNetWork({
      url: urlStr,
      success: (res) => {
        if (res.data.result === 1) {
          this.setData({
            name: res.data.data.name
          });

        } else {
          wx.showToast({
            title: res.data.msg,
            icon: "none"
          });
        }
      },
      fail: function (res) {
        console.log(res);
      }
    });
  },
  //tab 点击
  handleClick(evt) {
    let index = evt.detail.index;
    if (this.data.currentTabIndex !== index) {
      this.setData({
        currentTabIndex: index
      });
      this.getData();
    }
  },
  getData() {
    let urlStr = app.getNetAddresss("plugin.integral.Frontend.Modules.Integral.Controllers.Records");
    urlStr += '&index=' + this.data.currentTabIndex;
    app._getNetWork({
      url: urlStr,
      success: (res) => {
        if (res.data.result === 1) {
          this.setData({
            isLoadMore: true,
            page: 1,
            total_page: res.data.data.pageList.last_page,
            recordsList: res.data.data.pageList.data
          });
          if (!this.data.total_page) {
            this.setData({
              total_page: 0
            });
          }
        } else {
          wx.showToast({
            title: res.data.msg,
            icon: "none"
          });
        }
      },
      fail: function (res) {
        console.log(res);
      }
    });
  },
});